#include "../include/video.h"

/*
 * Putchar(int c)
 * 		Llama a write que es un system call;
 */
void
putchar (int c) {
    write (0, &c, 1);
}

void
printf (char *s, int len) {
    int i = 0;

    if (len <= 0)
        return;

    for (i = 0; i < len; i++)
        putchar (s[i]);
}



void
print (char *s) {
	int len=0;
    int i = 0;

    len = strlen(s);

    if (len <= 0)
        return;

    for (i = 0; i < len; i++)
        putchar (s[i]);
}
void
printd(int i){
	char *s=0x0;
	itoa(i,s);
	print(s);
}
void
scroll (char *donde, int cols, int filas) {
    int i;

    for (i = 0; i < (filas - 1) * cols * 2; i += 2) {
        donde[i] = donde[i + cols * 2];
        donde[i + 1] = donde[i + cols * 2 + 1];
    }
}

/* La siguiente funcion fue tomada de http://www.osdev.org */
void
update_cursor (int row, int col) {
    unsigned short position = (row * 80) + col;

    // cursor LOW port to vga INDEX register
    outb (0x3D4, 0x0F);
    outb (0x3D5, (unsigned char) (position & 0xFF));
    // cursor HIGH port to vga INDEX register
    outb (0x3D4, 0x0E);
    outb (0x3D5, (unsigned char) ((position >> 8) & 0x0FF));

}
